package com.zhuanzhuan.hero.user.facade;

import com.bj58.spat.scf.server.contract.annotation.ServiceBehavior;
import com.bj58.youpin.common.rpc.result.Result;
import com.bj58.zhuanzhuan.zzentry.common.service.entity.ServiceHeaderEntity;
import com.bj58.zhuanzhuan.zzentry.common.service.entity.ZZOpenScfBaseResult;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZHeader;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZMethod;
import com.bj58.zhuanzhuan.zzentry.common.service.model.openEntry.ZZParam;
import com.zhuanzhuan.hero.user.dto.UserContactDTO;
import com.zhuanzhuan.hero.user.service.HeroUserInfoService;
import com.zhuanzhuan.hero.user.vo.UserStoreVO;
import com.zhuanzhuan.hero.user.service.HeroUserContactService;
import com.zhuanzhuan.hero.user.util.ServiceHeaderUtil;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @ClassName UserContactFacadeImpl
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/20 21:35
 */
@ServiceBehavior
@Slf4j
public class UserContactFacadeImpl implements IUserContactFacade {

    @Resource
    private HeroUserContactService userContactService;

    @Resource
    private HeroUserInfoService userInfoService;

    @ZZMethod(value = "queryUserContactInfo", desc = "查询用户联系信息", publicAccess = false)
    @Override
    public ZZOpenScfBaseResult<UserContactDTO> queryUserContactInfo(@ZZHeader ServiceHeaderEntity header) {
        return ZZOpenScfBaseResult.buildSucc(userContactService.queryUserContactByUid(ServiceHeaderUtil.parseUid(header)));
    }

    @Override
    public Result<UserContactDTO> queryUserContactInfo(Long uid) {
        return Result.success(userContactService.queryUserContactByUid(uid));
    }

    @ZZMethod(value = "saveUserContactInfo", desc = "保存用户联系信息", publicAccess = false)
    @Override
    public ZZOpenScfBaseResult<Boolean> saveUserContactInfo(@ZZHeader ServiceHeaderEntity header,
        @ZZParam("param") @Valid UserContactDTO userContactDTO) {
        Long uid = ServiceHeaderUtil.parseUid(header);
        userInfoService.checkCanEdit(uid);
        userContactService.updateUserContact(uid, userContactDTO, header);
        return ZZOpenScfBaseResult.buildSucc(true);
    }

    @ZZMethod(value = "queryUserStore", desc = "查询用户店铺照片", publicAccess = false)
    @Override
    public ZZOpenScfBaseResult<UserStoreVO> queryUserStore(@ZZHeader ServiceHeaderEntity header,
        @NotNull Long targetUid) {
        return ZZOpenScfBaseResult.buildSucc(userContactService.queryUserStore(targetUid));
    }
}
